home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 May / PCPlus May 1998=disk A.iso / full / CBUILDER / SAMS / SAMPLES / CHAP04 / WRITEFIL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-12  |  793 b   |  34 lines

  1. #include <condefs.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <iostream.h>
  5. #include <fstream.h>
  6. #include <conio.h>
  7. #pragma hdrstop
  8.  
  9. int main(int argc, char **argv)
  10. {
  11.   char buff[81];
  12.   cout << "Creating File..." << endl;
  13.   ofstream outfile("test.dat");
  14.   if (!outfile) return 0;
  15.   cout << "Writing File..." << endl;
  16.   for (int i=0;i<10;i++) {
  17.     outfile << "This is line #" << i + 1 << endl;
  18.   }
  19.   outfile.close();
  20.   cout << "Opening File for Input..." << endl;
  21.   ifstream infile("test.dat");
  22.   if (!infile) return 0;
  23.   cout << "Reading File..." << endl << endl;
  24.   while (!infile.eof()) {
  25.       infile.getline(buff, sizeof(buff));
  26.     cout << buff << endl;
  27.   }
  28.   infile.close();
  29.   cout << endl << "Press any key to continue...";
  30.   getch();
  31.   return 0;
  32. }
  33.  
  34.